package com.atguigu.demo09mybatisplus.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MpConfig {

    @Bean
    public MybatisPlusInterceptor interceptor(){
        //mp全局拦截器
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        //mp分页拦截器: 要分页的数据库类型DbType.MYSQL
        PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(DbType.MYSQL);
        //配置分页合理化： 查询页码小于1 返回第一页，页码大于总页码返回最后一页
        paginationInnerInterceptor.setOverflow(true);
        //注册分页拦截器
        interceptor.addInnerInterceptor(paginationInnerInterceptor);
        return interceptor;
    }
}
